package geor.view;

import java.util.ArrayList;
import java.util.List;

import geor.app.R;
import geor.model.OpcaoRelatorio;
import android.content.ContentValues;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import lib.view.SimpleActivity;

public class ListaRelatoriosActivity extends SimpleActivity {

	private ListView listView = null;
	private List<OpcaoRelatorio> model = null;
	private ArrayAdapter<OpcaoRelatorio> adapter = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.lista_relatorios);
		
		load();
		set();
	}
	
	@Override
	public void createOrUpdate(ContentValues values) {
	}

	@Override
	public boolean delete(String id) {
		return false;
	}

	@Override
	public boolean validate(ContentValues values) {
		return false;
	}

	@Override
	public void load() {
		model = new ArrayList<OpcaoRelatorio>();
		model.add(new OpcaoRelatorio(0, "Resumo compras por mês"));
		model.add(new OpcaoRelatorio(1, "Compras no mês atual"));
		
		adapter = new ArrayAdapter<OpcaoRelatorio>(this, android.R.layout.simple_list_item_1, model);
		
		listView = (ListView) findViewById(R.id.lv_relatorios);
		listView.setAdapter(adapter);
	}

	@Override
	public void set() {
		listView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				OpcaoRelatorio opcao = model.get(position);
				switch (opcao.getId()) {
				case 0:
					go(GraficoActivity.class,
							GraficoActivity.TIPO_GRAFICO, String.valueOf(opcao.getId()));
					break;
				case 1:
					go(GraficoActivity.class,
							GraficoActivity.TIPO_GRAFICO, String.valueOf(opcao.getId()));
					break;
				}
			}
		});
	}

	@Override
	public void populate(ContentValues values) {
	}

}
